# {{ ansible_managed }}
global_defs {
    router_id VRRP_{{ ansible_hostname }}
{% if keepalived_vrrp_skip_check_adv_addr %}
    vrrp_skip_check_adv_addr
{% endif %}
{% if keepalived_vrrp_strict %}
    vrrp_strict
{% endif %}
}

{% if keepalived_vrrp_script is defined %}
{% for track in keepalived_vrrp_script %}
vrrp_script {{ track.name }} {
    script "{{ track.script }}"
{% if track.interval is defined %}
    interval {{ track.interval }}
{% endif %}
{% if track.rise is defined %}
    rise {{ track.rise }}
{% endif %}
{% if track.fall is defined %}
    fall {{ track.fall }}
{% endif %}
{% if track.weight is defined %}
    weight {{ track.weight }}
{% endif %}
}
{% endfor %}
{% endif %}

{% for vrrp in keepalived_vrrp_instance %}
vrrp_instance {{ vrrp.name }} {
    state MASTER
    interface {{ vrrp.interface }}
    virtual_router_id {{ vrrp.id }}
{% if vrrp.priority is defined %}
{% for p in vrrp.priority if p.name == ansible_hostname %}
    priority {{ p.priority }}
{% endfor %}
{% endif %}
{% if vrrp.advert_int is defined %}
    advert_int {{ vrrp.advert_int }}
{% endif %}
{% if vrrp.auth_pass is defined %}
    authentication {
        auth_type PASS
        auth_pass {{ vrrp.auth_pass }}
    }
{% endif %}
    virtual_ipaddress {
{% for vip in vrrp.vip %}
        {{ vip }}
{% endfor %}
    }
{% if vrrp.track_interface is defined %}
    track_interface {
{% for interface in vrrp.track_interface %}
        {{ interface }}
{% endfor %}
    }
{% endif %}
{% if vrrp.track_script is defined %}
    track_script {
{% for track in vrrp.track_script %}
        {{ track }}
{% endfor %}
    }
{% endif %}
{% if vrrp.nopreempt is defined and vrrp.nopreempt %}
    nopreempt
{% endif %}
}

{% endfor %}
